#include <iostream>

using namespace std;

typedef struct Node
{
	int data;
	struct Node * next;
}Node, * P;

P LinkedListCreat(int N);
void printLinkedList(P arr);
P dd(P pin);

int main(void)
{
	int N;

	cout << "N = ";
	cin >> N;

	P arr = LinkedListCreat(N);
//	printLinkedList(arr);

	arr -> next = dd(arr -> next);
//	P narr = (P)malloc(sizeof(Node));
//	narr -> next = arrn;

	printLinkedList(arr);

	return 0;
}

P LinkedListCreat(int N)
{
	P head;

	head = (P)malloc(sizeof(Node));
	P tail = head;
	tail -> next = NULL;

	for(int i = 0; i < N; i ++)
	{
		P p;
		p = (P)malloc(sizeof(Node));
		cout << "number" << i + 1 << " = ";
		cin >> p -> data;
		tail -> next = p;
		tail = p;
	}
	tail -> next = NULL;
	
	return head;
}

void printLinkedList(P arr)
{
	P p = arr -> next;
	int i = 0;
	while(p != NULL)
	{
		cout << "number" << i + 1 << " = " << p -> data << endl;
		p = p -> next;
		i ++;
	}
}

P dd(P pin)
{
	if(pin -> next == NULL)
		return pin;
	P head = dd(pin -> next);

//	cout << pin -> data << endl;
	pin -> next -> next = pin;
	pin -> next = NULL;

	return head;
}
